<?php
/*
Plugin Name: BPDEV-FORUMS-EXCERPT
Plugin URI: http://buddypressdev.org/plugins/bpdev-forums-excerpt
Description: It shows a excerpt of a definied number of words for last forums entry
Author: Nicola Greco
Version: 0.1
Author URI: http://buddypressdev.org
*/
/* Copyright (c) 2009-2011, Nicola Greco (mail: notsecurity@gmail.com | website: http://nicolagreco.com).

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

//edit here

$words = 70; //how many words to show

//stop editing

define( 'BPDEV_FEXCERPT_VERSION', '0.1' );
require_once( 'bp-core.php' );
if ($words != get_option('bpdev_fexcerpt_num')) update_option('bpdev_fexcerpt_num', $words);
function cut_text( $stringa ){
	$max_char = get_option('bpdev_fexcerpt_num');
	if( strlen( $stringa ) > $max_char ){
		$stringa_tagliata = substr( $stringa, 0, $max_char );
		$last_space = strrpos( $stringa_tagliata, " ");
		$stringa_ok = substr( $stringa_tagliata, 0,$last_space );
		return $stringa_ok." [...]";
	} else {
		return $stringa;
	}
}
if(!get_option('bpdev-fexcerpt-switcher')) add_option('bpdev-fexcerpt-switcher', 'on');
if(!get_option('bpdev_fexcerpt_num')) add_option('bpdev_fexcerpt_num', 145);
add_filter( 'bp_the_topic_latest_post_excerpt', 'cut_text' );
?>
